home *** CD-ROM | disk | FTP | other *** search
- /*[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]*/
- /* UPrinting.p */
- /* Copyright © 1986-1990 by Apple Computer Inc. All rights reserved. */
- #ifndef __UPrinting__
- #define __UPrinting__ 0
- #endif
- #if ! __UPrinting__
- #define __UPrinting__ 1
-
- /* • Required for this unit's interface. Auto-Include them */
- #ifndef __UMacApp__
- #include "UMacApp.h"
- #endif
- #ifndef __DIALOGS__
- #include "Dialogs.h"
- #endif
- #if ! qNeedsROM128K
- #ifndef __PRINTING__
- #include "Printing.h"
- #endif
- #else
- #ifndef __PRINTTRAPS__
- #include "PrintTraps.h"
- #endif
- #endif
-
- /* Command constants */
- const short cChangePrinterStyle = 192;
- /* Command arising from user's making changes
- in Page Setup... dialog */
- const short cShowBreaks = 201; /* “Show Page Breaks” command */
-
- /* Printing-related command numbers which apply only when a view with a non-null PrintHa
- ndler
- is in the target chain */
-
- /* Dialogs */
- const short phSpoolPrintDialog = 257; /* the dialog shown when printing a file (a
- misnomer - not just when spooled) */
- const short phFinderPrintDialog = 258; /* the dialog shown when doing Finder
- Printing; differs from prev. by addition
- of a 'Cancel All Printing' button */
-
- /* Alerts */
- const short phNoPages = 251; /* The “no pages within requested range”
- alert */
-
- /* Dialogs */
- const short phWhichDoc = 261; /* The “Preparing to print <docname>” dialog
- used during Finder printing */
-
- /* Miscellaneous */
- const short kUsualPages = SHRT_MAX; /* For methods that take a “pageNumber”
- argument, this value indicates a request
- for a general setting rather than a
- setting customized to one particular page
- */
-
- const short kNeverInitialized = SHRT_MAX; /* Pseudo-value for fPrinterDev field of
- TStdPrintHandler; used to trigger an
- initial PrinterChanged call */
-
- const long kPrintDriverName = 0xE000;
- /* STR resource in System file which contains
- name of the current print driver */
-
- struct PageAreas {
- Rect thePaper; /* physical page */
- Rect theInk; /* printable page */
- Rect theMargins;
- /* top-left positive; bottom-right negative */
- Rect theInterior;
- /* rect into which view-subset is projected */
- };
-
- class TStdPrintHandler : public TPrintHandler {
- public:
- /* Actually Implements all the features that
- were stubbed out in its ancestor. Basic
- flow of control at print time: Print,
-
- CheckPrinter, For each page(
- FocusOnBorder, DrawPageInterior,
-
- FocusOnBorder, AdornPage) are called. */
- PageAreas fPageAreas; /* metrics for printing */
-
- VRect fPrintExtent; /* the part of the view's extent that is to
- be printed by this print handler. The
- default is the entire extent, but it can
- be changed with the method SetAreaToPrint.
- */
-
- Boolean fFixedSizePages[2];
- /* Indicates whether pages are fixed size
- horzontally and vertically. */
-
- Handle fHPrint; /* actually of THPrint, a MacPrint type. The
- Print Record is 120 bytes long,
- and may be
- shared among all PrintHandlers in a
- document or may be unique to each
- PrintHandler, depending on the flag
- TDocument.fSharePrintInfo */
-
- Point fPageStrips; /* For printing a view which will take more
- than one page to print, the view is
- thought of as being divided up by vertical
- and horizontal lines ('page breaks') into
- a checkerboard of 'pages'. A vertical
- column, one page wide, of such pages is
- called a 'vertical page strip',
- while a
- horizontal row, one page high, of such
- pages is called a 'horizontal page strip'.
- The number of vertical page strips is
- represented by fPageStrips.v, and the
- number of horizontal page strips is
- represented by fPageStrips.h In a typical
- Word Processor application, there is only
- one vertical strip of pages, but many
- horizontal 'strips', each one only one
- page wide. In a graphical application,
-
- there may be many vertical as well as
- horizontal strips of pages. fPageStrips is
- recomputed by method CalcPageStrips. */
-
- short fStartPage;
- /* the page number for the topleftmost corner
- of the view. Normally 1, but can be set to
- any positive value */
-
- short fPrinterDev; /* MacPrint's device number for printer; use
- this at Print time for getting font
- metrics in device coordinates */
-
- long fLastCheckedPrinter; /* The time that the user's chosen Printer
- and my own idea of printer metrics were
- last known to be in harmony */
-
- StringHandle fLastPrinterName;
- /* The name of the current printer driver, at
- fLastCheckedPrinter. */
-
- VHSelect fPageDirection;
- /* Determines how page numbers are to advance
- in a large view which is more than one
- page wide and more than one page high; v
- means page 2 is BELOW page 1; h means it's
- to its RIGHT. Irrelevant if the view is
- only one page wide or only one page high */
-
- Boolean fShowBreaks; /* TRUE iff page breaks should be displayed
- at the moment */
-
- Boolean fFinderSetup;
- /* whether, during Finder Printing, the 'Page
- Setup' dialog should be presented to the
- user */
-
- Boolean fFinderJobDialog;
- /* whether, during Finder Printing, the Print
- Job dialog should be presented to the user
- (making it seem like “Print...”) or not
- (making it seem like “Print One”) */
-
- Boolean fSquareDots;
- /* if TRUE, then in the initial instance, use
- 72 x 72 resolution by default on
- ImageWriter; if FALSE, then full 80 x 72
- is used. This flag has no significance if
- the default printer at the time of
- creation of the printHandler is not an
- ImageWriter */
- Boolean fMinimalMargins; /* If TRUE, page margins are maintained such
- that exactly the complete printable area
- of the page is used. */
-
- Point fLastStrip; /* The last strip printed. */
-
- VPoint fLastBreak;
- /* The coordinates of the last page break. */
-
- VRect fViewedRect; /* The part of the view shown on the
- "current" page. Set by SetPage. */
-
- Point fMarginRes; /* Used when computing margins */
-
- GrafPtr fPrintDialog;
- /* Used for all printing-related dialogs. ???
- (shouldn't this really be a view (or
- TDialogView if using UDialog) */
- TPPrPort fPPrPort; /* Printer Port in use during printing */
- /* Initialization/Termination */
- virtual pascal void IStdPrintHandler(TDocument *itsDocument, TView *itsView, Boolean
- itsSquareDots, Boolean itsHFixedSize, Boolean itsVFixedSize);
- /* Initializes the printHandler and installs it in the view; if 'itsSquareDots' is
- TRUE, then a default print record for the ImageWriter world will use square dots
- ('tall adjusted') rather than rectangular ones; this sacrifices a bit of resolution
- but ensures that graphics will appear undistorted on the printed page */
-
- virtual pascal void Free(void);
-
- /* If relevant, frees the PrintInfo record and does other cleanup before freeing SELF
- */
-
- /* Page Strips */
-
- virtual pascal void CalcPageStrips(Point *pageStrips);
- /* Recalculate the number of strips of pages in each dimension */
-
- virtual pascal void CalcViewPerPage(VPoint *amtPerPage);
- /* Decide how much view (h and v) normally gets mapped into page interiors */
-
- virtual pascal VCoordinate BreakFollowing(VHSelect vhs, VCoordinate prevBreak, Boolean *
- automatic);
- /* Returns the location of the page break which follows the page break located at
- 'prevBreak', in direction vhs; returns automatic = TRUE if the page-break is
- thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note that
- page-breaks in dimension 'v' are drawn as vertical lines, those in dimension 'h' as
- horizontal lines. Generic support at present is only provided for 'automatic' page
- breaks; the 'automatic' parameter in BreakFollowing is a hook to allow clients to
- support manual page breaks as well */
-
- virtual pascal void EachBreak(VHSelect vhs, Boolean includeLast, pascal Boolean (*DoToBreak)(
- VCoordinate loc, Boolean automatic, void *DoToBreak_StaticLink), void *DoToBreak_StaticLink);
-
- /* Iterates through all page-breaks in the dimension given by vhs, or until DoToBreak
- returns true; the trailing edge of the view (i.e., right or bottom edge) is given
- as the final break if 'includeLast' is TRUE. The function 'DoToBreak' is called
- once for each page break in the chosen dimension */
-
- virtual pascal void GetBreakCoord(VHSelect vhs, short whichBreak, VCoordinate *loc);
- /* Returns, in 'loc', the coordinate of the 'whichBreak-th' page break in dimension
- vhs. For example, GetBreakCoord(v, 5, loc) will return, in 'loc', the horizontal
- coordinate of the vertical line (page-break) which marks the boundary the area of
- the view which will be mapped into the 4th vertical strip of pages and the area of
- the view which will be mapped into the 5th vertical strip of pages */
-
- virtual pascal Point PageToStrip(short pageNumber);
- /* Returns the horizontal and vertical strip for the given page. */
-
- virtual pascal short StripToPage(short hStrip, short vStrip);
- /* Returns the page number for the given page strip. */
-
- virtual pascal Point PointToPageStrip(VPoint *pointInView);
- /* Returns the page strip for a given point in view space. */
-
- /* General Utility */
-
- virtual pascal void GetDocName(StringPtr docName);
- /* Returns the name of the document being printed, for use in the print dialog. */
-
- virtual pascal void DoInMacPrint(pascal void (*WhatToDo)(void *WhatToDo_StaticLink), void *
- WhatToDo_StaticLink);
- /* If printing code is available, open the Print Driver, then call procedure
- “WhatToDo”, then close the Print Driver. If printing code not available,
- does
- nothing */
-
- virtual pascal void OpenPrintShop(void);
- /* Attempts to open the print shop by calling PrOpen. Signals failure if an error
- occurs. Called from DoInMacPrint. */
-
- virtual pascal void ClosePrintShop(void);
- /* Closes the print shop by calling PrClose. DOES NOT signal failure if an error
- occurs, only reports it to the debug window. */
-
- virtual pascal short MaxPageNumber(void);
- /* Returns the highest page number which would be printed if the user requested that
- “all pages” be printed */
-
- virtual pascal void AdornPage(void);
- /* Draw things on page # 'aPageNumber' which do not arise from the View but rather
- from page considerations; examples: Headers and Footers; page numbers; frames drawn
- around inset text; row and column headers for spreadsheets. */
-
- virtual pascal void ChooseSpoolFile(StringPtr spoolFileName, short *spoolVRefNum, short *
- pagesPerSubjob);
-
- /* Select the filename and volume to use for spooling; default chooses empty string on
- vol 0, which results in MacPrint's automatically choosing the local Boot volume */
-
- virtual pascal void DrawPageInterior(void);
- /* Make the QuickDraw calls which will result in the 'Interior' of page #
- 'aPageNumber' being drawn. The 'Interior' is those things on the page which arise
- from drawing the View associated with the PrintHandler */
-
- virtual pascal void FocusOnBorder(void);
- /* Set up GrafPort, clipping, etc., prior to calling AdornPage */
-
- virtual pascal void FocusOnInterior(void);
- /* Set up the GrafPort, clipping, etc., prior to calling DrawPageInterior */
-
- virtual pascal void LocatePageInterior(short pageNumber, Point *loc);
- /* Determine where to locate the top-left corner of the Interior of the given page
- nuamber */
-
- virtual pascal TCommand *OneSubJob(short subjobFirstPage, short subjobLastPage, Boolean
- justSpool, Boolean partialJob, Boolean *ranOutOfSpace, short *lastPageTried, Boolean *proceed
- );
- /* Processes one subjob for printing. Where appropriate, a print job is divided
- automatically into one or more 'subjobs', so that a long document can be printed
- even if there is very limited spool space available on the disk. This is a
- generalization of the 'spool-a-page/print-a-page' technique. TStdPrintHandler will
- use a subjob size as large as can be handled by current conditions, and will only
- fall back to more subjobs, each of smaller size, if it experiences problems running
- with a larger subjob size */
-
- virtual pascal TCommand *Print(CmdNumber itsCmdNumber, Boolean *proceed);
- /* Carries out printing for the print handler. */
-
- virtual pascal void PrintPage(short aPageNumber);
- /* Print the indicated page */
-
- virtual pascal void SetPage(short aPageNumber);
- /* Forwards to TView.DoSetInterior and TView.DoSetPageOffset */
-
- virtual pascal void SetPageInterior(short pageNumber);
- /* Responsible for installing the correct values into fPageAreas.theInterior,
-
- representing the 'interior' of the page in View coordinates */
-
- virtual pascal void SetPageOffset(VPoint *coord);
- /* Given the view-coordinate of the top-left-most point of the view which is mapped
- into the interior of this page, calculate and set the offset for the print code. */
-
- /* Formatting for printing and other Setup methods */
-
- virtual pascal void CheckPrinter(void);
- /* Check to see if user has changed printer specifications; if so, react */
-
- virtual pascal void InstallMargins(Rect *newMargins, Boolean areMinimalMargins);
-
- /* Install the (possibly new) margins specified; if 'areMinimalMargins' is TRUE, then
- the minimal-margins scheme is used; in this scheme, margins are always maintained
- at exactly the size necessary to have the page Interior coincide exactly with the
- printable area of the page */
-
- virtual pascal void PrinterChanged(void);
-
- /* After printer specifications have changed, absorb the new metrics and reformat the
- view if necessary */
-
- virtual pascal void RedoPageBreaks(void);
- /* Recalculate the page breaks */
-
- virtual pascal void Reset(void);
- /* Reset print record to default */
-
- virtual pascal void SetDefaultPrintInfo(void);
- /* Create a PrintInfo record and initialize it to default values */
-
- virtual pascal void SetPrintExtent(void);
-
- /* Sets the part of the print handler's view that is printed by this print handler, by
- calling the view's GetPrintExtent. */
-
- virtual pascal void SetMargins(void);
- /* Install the desired page margins */
-
- virtual pascal void ValidatePrintRecord(Boolean *didChange);
- /* Make certain that the current Print Record is compatible with the user's current
- printer choice; 'didChange' is set to TRUE iff the kind of printer changed */
-
- /* Menu Commands */
-
- virtual pascal TCommand *DoMenuCommand(CmdNumber aCmdNumber);
- /* Handles 'show page breaks', among others */
-
- virtual pascal void DoSetupMenus(void);
- /* Sets up menus for 'show page breaks' and company */
-
- /* Finder Printing */
-
- virtual pascal Boolean SetupForFinder(void);
- /* Sets up the print record for finder printing. If fFinderPageSetup is true, then
- PosePageSetupDialog is called. If fFinderJobDialog is true, then PoseJobDialog is
- called. Otherwise, prJobMerge is called to merge the job record from the */
-
- virtual pascal Boolean SetupPrintOne(void);
-
- /* Sets up the print record for a "print one" type of operation, one where the entire
- document or view is printed and no job dialog takes place. Returns true if we
- should proceed. */
-
- /* Screen Feedback */
-
- virtual pascal void DrawPrintFeedback(Rect *area);
- /* Gateway to all screen feedback related to pagination issues */
-
- virtual pascal void DrawPageBreak(VHSelect vhs, short whichBreak, VCoordinate loc, Boolean
- automatic);
- /* Draws a page break on the screen. */
-
- virtual pascal void InvalPageFeedback(void);
- /* Invalidates all page-related screen feedback */
-
- virtual pascal Boolean ShowsOnScreen(void);
- /* Returns TRUE only if the printHandler has an fView which is in an open window. */
-
- /* Dialogs relating to printing */
-
- virtual pascal Boolean PoseJobDialog(void);
- /* Pose the 'Print Job' dialog */
-
- virtual pascal TCommand *PosePageSetupDialog(Boolean *proceed, Boolean isUndoable);
- /* Undertake the 'Page Setup' dialog; return a command object to be performed if
- relevant */
-
- virtual pascal void PosePrintDialog(void);
- /* Put up the 'Printing in Progress' dialog */
-
- virtual pascal void ShowDocBeingPrinted(Boolean entering);
-
- /* Put up (or remove) a window whose title is the document's title, because the Print
- Manager gets the document title from the front window. */
-
- virtual pascal void BanishPrintDialog(void);
- /* Get rid of the print dialog. */
-
- virtual pascal void DoPrintIdling(void);
- /* Print job idle time handler. Handles events in the 'Print Dialogs' which give the
- user 'Cancel', and, in the case of printing from the Finder, 'Cancel All Printing.
- */
-
- virtual pascal void ChkPrintErr(OSErr *err, Boolean *proceed, Boolean *ranOutOfSpace);
- /* Checks for a MacPrint error, but only if 'proceed' is TRUE on entry; specially
- handles one particular error (sets return parameter 'ranOutOfSpace' if error code
- indicates disk-space problem while saving a spool file). */
-
- virtual pascal void PrintSpoolFile(Handle anHPrint, OSErr *err, Boolean *proceed);
- /* If printing was spooled by the print-driver then this Method will be called
- to print the spooled image. */
-
- virtual pascal void GetDriverName(StringPtr driverName);
- /* Get the name of the current printer driver. */
-
- /* Debugging */
-
- virtual pascal void IdentifySoftware(void);
- /* Shows the version of the Printing Unit being used; display is in
- the Debug window */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this classes
- fields. */
- };
-
- /*--------------------------------------------------------------------------------------
- ------------*/
- class TPrintStyleChangeCommand : public TCommand {
- public:
- /* Used to allow changes made by the user in
- the 'Page Setup...' dialog to be
- undoable. */
-
- /* Fields */
-
- TStdPrintHandler *fStdPrintHandler; /* Associated print handler */
-
- Handle fOldHPrint;
- /* The old print record, before the change */
- Handle fNewHPrint; /* The new print record, after the change */
-
- /* Initialization and Termination */
-
- virtual pascal void IPrintStyleChangeCommand(TStdPrintHandler *itsPrintHandler);
- /* Initializes the print style change command, makes a copy of the old print handle
- and creates the new one. */
- virtual pascal void Free(void);
- /* Disposes the old and new print handles. */
-
- /* Command Execution */
-
- virtual pascal void DoIt(void);
- /* Calls CheckPrinter, finding it changed will dispatch to views DoPrinterChanged
- method. */
-
- virtual pascal void UndoIt(void);
-
- /* Copies the old print handle back and calls CheckPrinter which will in turn call the
- views DoPrinterChanged method. */
-
- virtual pascal void RedoIt(void);
-
- /* Copies the new print handle back and calls CheckPrinter which will in turn call the
- views DoPrinterChanged method. */
-
- /* Debugging */
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- /*--------------------------------------------------------------------------------------
- ------------*/
- class TPrintCommand : public TNoChangesCommand {
- public: /* Returned in response to a printing
- request. Doesn't actually do the
- printing itself, but forwards to the
- appropriate handler. */
-
- TStdPrintHandler *fStdPrintHandler; /* the associated print handler */
-
- virtual pascal void IPrintCommand(CmdNumber itsCmdNumber, TStdPrintHandler *itsStdPrintHandler);
- /* Initialize the PrintCommand procedurally */
-
- virtual pascal void DoIt(void);
- /* Tell the print handler to print */
-
- virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short
- fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
- /* Used by the Inspector and the Debugger to display the contents of this class's
- fields. */
-
- };
-
- extern pascal PenState gBreaksPenState; /* penState to used to draw page breaks */
- extern pascal Boolean gCancelAllPrinting;
- /* set to TRUE if during Finder Printing user
- selects “Cancel All” */
- extern pascal Rect gStdPageMargins; /* "Standard" left, top, right, bottom page
- margins, in screen resolution - one inch
- all round by default */
- extern pascal Handle gFinderHPrint;
- /* Used for finder printing, to do PrJobMerge
- when printing more than one document. */
-
- extern pascal TStdPrintHandler *gJobPrintHandler; /* The Print Handler in use during printing.
- */
-
- /* Initialization */
-
- extern pascal void InitUPrinting(void);
- /* Call once, at application start-up time. You can interrogate global variable 'gCouldP
- rint'
- at any time to determine whether printing code is actually accessible */
-
- extern pascal void InitPrinting(void);
- /* Synonym for InitUPrinting. Left in for compatibility (2.0) */
-
- extern pascal void IdleProcForTStdPrintHandler(void);
- /* Procedure whose address is passed to the print job for calling as often as possible.
- Forwards to the DoPrintIdling method of the job's print handler. */
-
- #endif
-
-